package com.yt.web.unit;

import java.util.Random;

public class CreateCodeUtil {

    /**
     * 邮件验证码
     * @return
     */
    public static String getEmailValidateCode() {
        Random random = new Random();
        //取1000-9999随机数
        String code = Integer.valueOf(random.nextInt(8000) + 1000).toString();
        return code;
    }

    /**
     * 短信验证码
     * @return
     */
    public static String getSmsValidateCode() {
        Random random = new Random();
        //取 100000-999999随机数
        String code = Integer.valueOf(random.nextInt(800000) + 100000).toString();
        return code;
    }

    /**
     * 生成email验证码,verfiyLink中的verifyCode
     * @param memberId
     * @param verifyCode
     * @return
     */
    public static String generateEmailVerifyCode(Integer memberId, String verifyCode) {
        String code = memberId + "@@" + verifyCode;
        String generateEmailVerifyCode = Md5.getMd5String(code).substring(0, 16);
        return generateEmailVerifyCode;
    }

    /**
     * 随机生成6为密码  数字 小写大写字母
     * @return
     */
    public static String generatePassword() {
        String[] pwArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d",
                "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w",
                "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N",
                "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        String password = "";
        Random random = new Random();
        int i = 0;
        do {
            i++;
            int randomValue = Integer.valueOf(random.nextInt(55));
            password += pwArray[randomValue];
        } while (i < 6);

        return password;
    }

}
